#006-选考难度B-数据解压缩-201604-17学考选考，gui版
import tkinter as tk
from tkinter.constants import N
from tkinter.font import nametofont
from typing import Counter

def unzip():
    '''解压缩'''
    alst = list(map(int,txt1.get().split(',')))
    blst = []
    if not alst:
        print('输入有误，使用默认数据.')
        alst = [25,0,0,0,7,78]
    n=len(alst)
    pa = 0 
    #pb = 0
    #count = 0
    while pa < n:
        firstdata = alst[pa]
        if firstdata != 0:
            blst.append(firstdata)
            pa = pa + 1 
            #pb = pb + 1
        else:
            count = alst[pa+1]
            if count == 0:
                blst.append(0)
                pa = pa + 2
                #pb = pb + 1
            else:
                for i  in range(count):
                    blst.append(alst[pa+2])
                pa = pa + 3
                #pb = pb + count
    txt2.insert(0,','.join([str(x) for x in blst]))

# 建立窗口
win = tk.Tk()
win.title('数据解压缩')
win.resizable(0, 0)
# 建立组件
lb1 = tk.Label(win, text = '压缩数据')
lb2 = tk.Label(win, text = '解压缩数据')
txt1 = tk.Entry(win,width=40)
txt1.insert(0, '25,0,0,0,7,78')
txt2 = tk.Entry(win,width=40)
cmd = tk.Button(win, text = '解压缩', command = unzip)

# 组件布局
lb1.grid(row=0, column=0)
lb2.grid(row=1, column=0)
txt1.grid(row=0, column=1)
txt2.grid(row=1, column=1)
cmd.grid(row=2,column=1)


# 接收窗口事件
win.mainloop()




